﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace SmartWaterMointerCenter.Utils
{
    public class XMLHelper
    {
        //添加XML文档声明节点
        public static void CreateNewXml(XmlDocument doc, string rootName)
        {
            doc.AppendChild(doc.CreateXmlDeclaration("1.0", "UTF-8", null));
            XmlElement root = doc.CreateElement(rootName);
            doc.AppendChild(root);
        }

        //添加节点---包含子节点
        public static XmlElement AddElement(XmlDocument doc, string nodeName, XmlElement pNode)
        {
            XmlElement ele = doc.CreateElement(nodeName);
            pNode.AppendChild(ele);
            return ele;
        }
        //添加节点---包含节点文本
        public static void AddElement(XmlDocument doc, string nodeName, XmlElement pNode, string value)
        {
            XmlElement ele = doc.CreateElement(nodeName);
            ele.InnerText = value;
            pNode.AppendChild(ele);
        }

        //添加属性
        public static void AddAttribute(XmlDocument doc, string attrName, XmlElement node, string value)
        {
            XmlAttribute attr = doc.CreateAttribute(attrName);
            attr.Value = value;
            node.Attributes.Append(attr);
        }
    }
}
